<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="帖子标题" prop="topicTitle">
        <el-input
          v-model="queryParams.topicTitle"
          placeholder="请输入帖子标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="审核状态" prop="topicStatus">
        <el-select
          v-model="queryParams.topicStatus"
          placeholder="请选择审核状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.f_topic_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="informationList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="序号"
        type="index"
        :index="table_index"
        width="50"
        align="center"
      >
      </el-table-column>
      <el-table-column label="帖子标题" align="center" prop="topicTitle" />
      <el-table-column
        label="发帖人姓名"
        align="center"
        prop="sysUser.userName"
      />
      <el-table-column
        label="发帖人昵称"
        align="center"
        prop="sysUser.nickName"
      />
      <el-table-column
        label="发帖人电话"
        align="center"
        prop="sysUser.phonenumber"
      />
      <el-table-column
        label="发帖人邮箱"
        align="center"
        prop="sysUser.email"
      /><el-table-column label="发帖时间" align="center" prop="createTime" />
      <el-table-column label="审核状态" align="center" prop="topicStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.f_topic_status"
            :value="scope.row.topicStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleContent(scope.row)"
            >查看内容
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleAdd(scope.row)"
            v-show="scope.row.topicStatus == 0"
            >通过</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-show="scope.row.topicStatus == 0"
            >不通过</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改帖子管理对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
    <!--查看公告内容-->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form">
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-tag size="medium" style="font-size: 15px">{{
                form.topicTitle
              }}</el-tag>
            </el-form-item>
          </el-col>

          <el-col :span="24" style="margin-top: -22px">
            <el-divider
              ><i class="el-icon-star-off" style="margin-right: 3px"></i
              >帖子标题</el-divider
            >
          </el-col>
          <el-col :span="24" style="margin-top: 10px">
            <el-form-item>
              <el-card>
                <el-col>
                  <div
                    v-html="form.topicContent"
                    class="content demo-image__lazy"
                  ></div>
                </el-col>
              </el-card>
            </el-form-item>
          </el-col>
          <el-col>
            <!-- <image-preview :src="form.feedbackPhoto" /> -->
            <el-card>
              <div class="block" v-if="srcListTrue == 0">
                <el-carousel
                  :autoplay="false"
                  indicator-position="outside"
                  height="300px"
                >
                  <el-carousel-item v-for="item in srcList" :key="item">
                    <image-preview :src="item" />
                  </el-carousel-item>
                </el-carousel>
              </div>
              <div v-if="srcListTrue == 2" align="center">占无内容</div>
              <div v-if="srcListTrue == 1">
                <VideoPlay
                  :videoUrl="form.topicVideo"
                  :width="780"
                  :height="300"
                  :autoplay="false"
                  :controls="true"
                  :loop="false"
                  :muted="false"
                  preload="auto"
                  :playWidth="96"
                  zoom="none"
                />
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <!--查看帖子内容-->
    <el-dialog
      :title="title"
      :visible.sync="openContent"
      width="780px"
      align="center"
      append-to-body
    >
      <el-form
        ref="formContent"
        :model="formContent"
        :rules="rules"
        label-width="80px"
      >
        <el-row>
          <el-col :span="24">
            <el-form-item label="理由" prop="msgContent">
              <editor v-model="formContent.msgContent" :min-height="192" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  listInformation,
  getInformation,
  delInformation,
  addInformation,
  updateInformation,
} from "@/api/topic/information";

import VideoPlay from "@/components/VideoPlay";
export default {
  components: {
    VideoPlay,
  },
  name: "Information",
  dicts: ["f_topic_status"],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 帖子管理表格数据
      informationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //查看内容弹出层
      openContent: false,
      // 是否删除时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        topicTitle: undefined,
        topicStatus: undefined,
        createTime: undefined,
      },
      // 表单参数
      form: {},
      formContent: {},
      // 表单校验
      rules: {},
      //图片路径集合
      srcList: [],
      srcListTrue: 2,
      rules: {
        msgContent: [
          { required: true, message: "审核内容不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //序号换页问题
    table_index(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 查询帖子管理列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && "" != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] =
          this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listInformation(this.queryParams).then((response) => {
        this.informationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openContent = false;
      this.resetContent();
    },
    // 表单重置
    resetContent() {
      this.formContent = {
        msgContent: undefined,
      };
      this.resetForm("formContent");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 不通过按钮操作 */
    handleUpdate(row) {
      this.resetContent();
      this.formContent = row;
      this.openContent = true;
      this.title = "审核管理";
    },
    /** 查看帖子内容 */
    handleContent(row) {
      this.loading = true;
      const topicId = row.topicId;
      getInformation(topicId).then((response) => {
        this.loading = false;
        this.form = response.data;
        if (this.form.topicImgList != null) {
          this.srcListTrue = 0;
          this.srcList = this.form.topicImgList.split(",");
        } else if (this.form.topicVideo != null) {
          this.srcListTrue = 1;
        } else {
          this.srcListTrue = 2;
        }
        this.open = true;
        this.title = "查看帖子内容";
      });
    },
    /** 通过操作 */
    handleAdd(row) {
      const topicIds = row.topicId;
      this.$modal
        .confirm('是否确认通过帖子编号为"' + topicIds + '"的数据项？')
        .then(() => {
          this.loading = true;
          this.buttonLoading = true;
          this.formContent = row;
          return updateInformation(this.formContent);
        })
        .then(() => {
          this.loading = false;
          this.buttonLoading = false;
          this.getList();
          this.$modal.msgSuccess("审核成功");
        })
        .catch(() => {});
    },
    /** 不通过提交按钮 */
    submitForm() {
      this.$refs["formContent"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          updateInformation(this.formContent)
            .then((response) => {
              this.$modal.msgSuccess("审核成功");
              this.openContent = false;
              this.getList();
            })
            .catch(() => {})
            .finally(() => {
              this.buttonLoading = false;
            });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const topicIds = row.topicId;
      this.$modal
        .confirm('是否确认删除帖子管理编号为"' + topicIds + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delInformation(topicIds);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
  },
};
</script>
<style scoped>
.demo-image__lazy {
  height: 200px;
  overflow-y: auto;
}
.demo-image__lazy .el-image {
  display: block;
  min-height: 200px;
  margin-bottom: 10px;
}
.demo-image__lazy .el-image:last-child {
  margin-bottom: 0;
}
.el-dialog {
  display: flex;
  flex-direction: column;
  margin: 0 !important;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-height: calc(100% - 30px);
  max-width: calc(100% - 30px);
}
.content {
  text-indent: 2em;
}
</style>
  